from sklearn.datasets import load_iris, fetch_20newsgroups, load_boston
from sklearn.model_selection import train_test_split, GridSearchCV
from sklearn.neighbors import KNeighborsClassifier
from sklearn.preprocessing import StandardScaler
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.naive_bayes import MultinomialNB
from sklearn.metrics import classification_report
from sklearn.feature_extraction import DictVectorizer
from sklearn.tree import DecisionTreeClassifier, export_graphviz
from sklearn.ensemble import RandomForestClassifier
import pandas as pd

li = load_iris()

# 第一例子：sklearn分类数据集
print("获取特征值")
print(li.data)
print("目标值")
print(li.target)
print(li.DESCR)

# 第二例子：数据集进行分割
# 注意返回值, 训练集 train  x_train, y_train        测试集  test   x_test, y_test
# 训练集特征值，测试集特征值，训练标签，测试标签 (默认随机取)
x_train, x_test, y_train, y_test = train_test_split(li.data, li.target, test_size=0.25)

print("训练集特征值和目标值：", x_train, y_train)
print("测试集特征值和目标值：", x_test, y_test)

# 第三个例子：用于分类的大数据集
news = fetch_20newsgroups(subset='all')

print(news.data)
print(news.target)

# 第四个例子：sklearn回归数据集
lb = load_boston()

print("获取特征值")
print(lb.data)
print("目标值")
print(lb.target)
print(lb.DESCR)